// var i;
// var $bundleConfig = require("./BundleConfig");
// var $resKeeper = require("./ResKeeper");
// var d = cc._decorator;
// var p = d.ccclass;
// var h = (d.property, d.inspector);
// var f = (function (e) {
//     function t() {
//         var t = (null !== e && e.apply(this, arguments)) || this;
//         t.state = 1;
//         t.offtime = 0;
//         return t;
//     }
//     __extends(t, e);
//     t.prototype.onEnable = function () {};
//     t.prototype.startJianTou = function () {
//         return __awaiter(this, void 0, void 0, function () {
//             var e;
//             var t;
//             var o;
//             return __generator(this, function (n) {
//                 switch (n.label) {
//                     case 0:
//                         switch (((e = null), (t = null), (o = null), this.state)) {
//                             case 1:
//                                 return [3, 1];
//                             case 2:
//                                 return [3, 5];
//                             case 3:
//                                 return [3, 9];
//                         }
//                         return [3, 13];
//                     case 1:
//                         return [4, this._loadRes($bundleConfig.BundleNames.Game, "res/jian1", cc.SpriteFrame)];
//                     case 2:
//                         e = n.sent();
//                         this.node.children[2].getComponent(cc.Sprite).spriteFrame = e;
//                         return [4, this._loadRes($bundleConfig.BundleNames.Game, "res/jian3", cc.SpriteFrame)];
//                     case 3:
//                         t = n.sent();
//                         this.node.children[1].getComponent(cc.Sprite).spriteFrame = t;
//                         return [4, this._loadRes($bundleConfig.BundleNames.Game, "res/jian3", cc.SpriteFrame)];
//                     case 4:
//                         o = n.sent();
//                         this.node.children[0].getComponent(cc.Sprite).spriteFrame = o;
//                         this.state = 2;
//                         return [3, 13];
//                     case 5:
//                         return [4, this._loadRes($bundleConfig.BundleNames.Game, "res/jian2", cc.SpriteFrame)];
//                     case 6:
//                         e = n.sent();
//                         this.node.children[2].getComponent(cc.Sprite).spriteFrame = e;
//                         return [4, this._loadRes($bundleConfig.BundleNames.Game, "res/jian1", cc.SpriteFrame)];
//                     case 7:
//                         t = n.sent();
//                         this.node.children[1].getComponent(cc.Sprite).spriteFrame = t;
//                         return [4, this._loadRes($bundleConfig.BundleNames.Game, "res/jian3", cc.SpriteFrame)];
//                     case 8:
//                         o = n.sent();
//                         this.node.children[0].getComponent(cc.Sprite).spriteFrame = o;
//                         this.state = 3;
//                         return [3, 13];
//                     case 9:
//                         return [4, this._loadRes($bundleConfig.BundleNames.Game, "res/jian3", cc.SpriteFrame)];
//                     case 10:
//                         e = n.sent();
//                         this.node.children[2].getComponent(cc.Sprite).spriteFrame = e;
//                         return [4, this._loadRes($bundleConfig.BundleNames.Game, "res/jian2", cc.SpriteFrame)];
//                     case 11:
//                         t = n.sent();
//                         this.node.children[1].getComponent(cc.Sprite).spriteFrame = t;
//                         return [4, this._loadRes($bundleConfig.BundleNames.Game, "res/jian1", cc.SpriteFrame)];
//                     case 12:
//                         o = n.sent();
//                         this.node.children[0].getComponent(cc.Sprite).spriteFrame = o;
//                         this.state = 1;
//                         return [3, 13];
//                     case 13:
//                         return [2];
//                 }
//             });
//         });
//     };
//     t.prototype.update = function (e) {
//         this.offtime += e;
//         if (this.offtime >= 0.3) {
//             this.offtime = 0;
//             this.startJianTou();
//         }
//     };
//     return __decorate([p], t);
// })($resKeeper.default);
// exports.default = f;


// import { BundleNames } from './BundleConfig';
// import ResKeeper from './ResKeeper';

// const { ccclass, property, inspector } = cc._decorator;

// /**
//  * @class f
//  * 建议类名：ArrowController
//  * 用于管理箭头状态的控制器类。
//  */
// @ccclass
// export default class UI_JianTou extends ResKeeper {
//     /** 当前状态 */
//     private state: number = 1;

//     /** 离线时间累计 */
//     private offtime: number = 0;

//     /**
//      * 当节点启用时调用
//      * 建议方法名：handleEnable
//      */
//     onEnable() {
//         // 可以在此实现需要的逻辑
//     }

//     /**
//      * 异步启用箭头
//      * 建议方法名：startArrow
//      */
//     async startJianTou(): Promise<void> {
//         let spriteFrame1: cc.SpriteFrame | null = null;
//         let spriteFrame2: cc.SpriteFrame | null = null;
//         let spriteFrame3: cc.SpriteFrame | null = null;

//         switch (this.state) {
//             case 1:
//                 spriteFrame1 = await this._loadRes(BundleNames.Game, "res/jian1", cc.SpriteFrame);
//                 if (this.node.children[2]?.getComponent(cc.Sprite)) {
//                     this.node.children[2].getComponent(cc.Sprite)!.spriteFrame = spriteFrame1;
//                 }
//                 spriteFrame2 = await this._loadRes(BundleNames.Game, "res/jian3", cc.SpriteFrame);
//                 if (this.node.children[1]?.getComponent(cc.Sprite)) {
//                     this.node.children[1].getComponent(cc.Sprite)!.spriteFrame = spriteFrame2;
//                 }
//                 spriteFrame3 = await this._loadRes(BundleNames.Game, "res/jian3", cc.SpriteFrame);
//                 if (this.node.children[0]?.getComponent(cc.Sprite)) {
//                     this.node.children[0].getComponent(cc.Sprite)!.spriteFrame = spriteFrame3;
//                 }
//                 this.state = 2;
//                 break;

//             case 2:
//                 spriteFrame1 = await this._loadRes(BundleNames.Game, "res/jian2", cc.SpriteFrame);
//                 if (this.node.children[2]?.getComponent(cc.Sprite)) {
//                     this.node.children[2].getComponent(cc.Sprite)!.spriteFrame = spriteFrame1;
//                 }
//                 spriteFrame2 = await this._loadRes(BundleNames.Game, "res/jian1", cc.SpriteFrame);
//                 if (this.node.children[1]?.getComponent(cc.Sprite)) {
//                     this.node.children[1].getComponent(cc.Sprite)!.spriteFrame = spriteFrame2;
//                 }
//                 spriteFrame3 = await this._loadRes(BundleNames.Game, "res/jian3", cc.SpriteFrame);
//                 if (this.node.children[0]?.getComponent(cc.Sprite)) {
//                     this.node.children[0].getComponent(cc.Sprite)!.spriteFrame = spriteFrame3;
//                 }
//                 this.state = 3;
//                 break;

//             case 3:
//                 spriteFrame1 = await this._loadRes(BundleNames.Game, "res/jian3", cc.SpriteFrame);
//                 if (this.node.children[2]?.getComponent(cc.Sprite)) {
//                     this.node.children[2].getComponent(cc.Sprite)!.spriteFrame = spriteFrame1;
//                 }
//                 spriteFrame2 = await this._loadRes(BundleNames.Game, "res/jian2", cc.SpriteFrame);
//                 if (this.node.children[1]?.getComponent(cc.Sprite)) {
//                     this.node.children[1].getComponent(cc.Sprite)!.spriteFrame = spriteFrame2;
//                 }
//                 spriteFrame3 = await this._loadRes(BundleNames.Game, "res/jian1", cc.SpriteFrame);
//                 if (this.node.children[0]?.getComponent(cc.Sprite)) {
//                     this.node.children[0].getComponent(cc.Sprite)!.spriteFrame = spriteFrame3;
//                 }
//                 this.state = 1;
//                 break;

//             default:
//                 break;
//         }
//     }

//     /**
//      * 每帧更新
//      * @param delta 增量时间
//      * 建议方法名：updateFrame
//      */
//     update(delta: number): void {
//         this.offtime += delta;
//         if (this.offtime >= 0.3) {
//             this.offtime = 0;
//             this.startJianTou();
//         }
//     }

//     /**
//      * 加载资源
//      * @param bundleName 包名字
//      * @param path 资源路径
//      * @param type 资源类型
//      * @returns 加载的资源
//      * 建议方法名：loadResource
//      */
//     protected async _loadRes(
//         bundleName: string,
//         path: string,
//         type: typeof cc.Asset
//     ): Promise<cc.SpriteFrame> {
//         return new Promise((resolve, reject) => {
//             cc.assetManager.getBundle(bundleName)?.load(path, type, (err, asset) => {
//                 if (err) {
//                     reject(err);
//                 } else {
//                     resolve(asset as cc.SpriteFrame);
//                 }
//             });
//         });
//     }
// }

import { BundleNames } from './BundleConfig';
import ResKeeper from './ResKeeper';

const { ccclass, property, inspector } = cc._decorator;

/**
 * @class f
 * 建议类名：ArrowController
 * 用于管理箭头状态的控制器类。
 */
@ccclass
export default class ViewJianTou extends ResKeeper {
    /** 当前状态 */
    private state: number = 1;

    /** 离线时间累计 */
    private elapsedOfflineTime: number = 0;

    /**
     * 当节点启用时调用
     * 建议方法名：handleEnable
     */
    onEnable() {
        // 可以在此实现需要的逻辑
    }

    /**
     * 异步启用箭头
     * 建议方法名：startArrow
     */
    async startArrow(): Promise<void> {
        let spriteFrame1: cc.SpriteFrame | null = null;
        let spriteFrame2: cc.SpriteFrame | null = null;
        let spriteFrame3: cc.SpriteFrame | null = null;

        const setSpriteFrame = async (index: number, resPath: string) => {
            const sf = await this._loadRes(BundleNames.Game, resPath, cc.SpriteFrame);
            const sprite = this.node.children[index]?.getComponent(cc.Sprite);
            if (sprite) {
                sprite.spriteFrame = sf;
            }
            return sf;
        };

        switch (this.state) {
            case 1:
                spriteFrame1 = await setSpriteFrame(2, "res/jian1");
                spriteFrame2 = await setSpriteFrame(1, "res/jian3");
                spriteFrame3 = await setSpriteFrame(0, "res/jian3");
                this.state = 2;
                break;

            case 2:
                spriteFrame1 = await setSpriteFrame(2, "res/jian2");
                spriteFrame2 = await setSpriteFrame(1, "res/jian1");
                spriteFrame3 = await setSpriteFrame(0, "res/jian3");
                this.state = 3;
                break;

            case 3:
                spriteFrame1 = await setSpriteFrame(2, "res/jian3");
                spriteFrame2 = await setSpriteFrame(1, "res/jian2");
                spriteFrame3 = await setSpriteFrame(0, "res/jian1");
                this.state = 1;
                break;

            default:
                break;
        }
    }

    /**
     * 每帧更新
     * @param delta 增量时间
     * 建议方法名：updateFrame
     */
    update(delta: number): void {
        this.elapsedOfflineTime += delta;
        if (this.elapsedOfflineTime >= 0.3) {
            this.elapsedOfflineTime = 0;
            this.startArrow();
        }
    }

    /**
     * 加载资源
     * @param bundleName 包名字
     * @param path 资源路径
     * @param type 资源类型
     * @returns 加载的资源
     * 建议方法名：loadResource
     */
    protected async _loadRes(
        bundleName: string,
        path: string,
        type: typeof cc.Asset
    ): Promise<cc.SpriteFrame> {
        return new Promise((resolve, reject) => {
            cc.assetManager.getBundle(bundleName)?.load(path, type, (err, asset) => {
                if (err) {
                    reject(err);
                } else {
                    resolve(asset as cc.SpriteFrame);
                }
            });
        });
    }
}